﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharpGameLibrary;

namespace Editor
{
    public partial class FormMapProperties : Form
    {
        private Map map;

        public FormMapProperties(Map map)
        {
            InitializeComponent();

            this.map = map;

            this.initializeTextBoxes();
        }

        private void initializeTextBoxes()
        {
            textBox1.Text = this.map.AdjacentMaps.Item1.ToString();
            textBox2.Text = this.map.AdjacentMaps.Item2.ToString();
            textBox3.Text = this.map.AdjacentMaps.Item3.ToString();
            textBox4.Text = this.map.AdjacentMaps.Item4.ToString();
            textBox5.Text = this.map.AdjacentMaps.Item5.ToString();
            textBox6.Text = this.map.AdjacentMaps.Item6.ToString();
            textBox7.Text = this.map.AdjacentMaps.Item7.ToString();
            textBox8.Text = this.map.AdjacentMaps.Rest.Item1.ToString();
        }

        private void setAdjacentMaps()
        {
            string sNorth = textBox1.Text;
            string sEast = textBox2.Text;
            string sSouth = textBox3.Text;
            string sWest = textBox4.Text;
            string s1 = textBox5.Text;
            string s2 = textBox6.Text;
            string s3 = textBox7.Text;
            string s4 = textBox8.Text;

            if (sNorth == "")
                sNorth = "-1";
            if (sEast == "")
                sEast = "-1";
            if (sSouth == "")
                sSouth = "-1";
            if (sWest == "")
                sWest = "-1";
            if (s1 == "")
                s1 = "-1";
            if (s2 == "")
                s2 = "-1";
            if (s3 == "")
                s3 = "-1";
            if (s4 == "")
                s4 = "-1";

            int north, east, south, west, q, w, r, t;

            if (!(Int32.TryParse(sNorth, out north) && Int32.TryParse(sEast, out east) &&
                Int32.TryParse(sSouth, out south) && Int32.TryParse(sWest, out west) &&
                Int32.TryParse(s1, out q) && Int32.TryParse(s2, out w) &&
                Int32.TryParse(s3, out r) && Int32.TryParse(s4, out t)))
            {
                MessageBox.Show("Veuillez entrer un identifiant valide pour les maps adjacentes.",
                    "Attention",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning,
                    MessageBoxDefaultButton.Button1);
                return;
            }

            this.map.AdjacentMaps = new Tuple<int, int, int, int, int, int, int, Tuple<int>>(north, east, south, west, q, w, r, new Tuple<int>(t));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.setAdjacentMaps();

            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
